<template>
  <el-page-header icon="" title="我的管理系统">
    <template #content>
      <span class="text-large font-600 mr-3"> 首页 </span>
    </template>
  </el-page-header>
  <el-card class="box_card">
    <el-row>
      <el-col :span="4">
        <el-avatar :size="100" :src="circleUrl" />
      </el-col>
      <el-col :span="20">
        <h3 style="line-height: 100px;">
          欢迎 {{ store.state.userInfo.username }} 使用！
          当前时间为：{{ currentTime }}
        </h3>
      </el-col>
    </el-row>
  </el-card>
  <el-card class="box_card">
    <template #header>
      <div class="card-header">
        <span>公司产品</span>
      </div>
    </template>
    <el-carousel :interval="4000" type="card" height="200px">
      <el-carousel-item v-for="item in 6" :key="item">
        <h3 text="2xl" justify="center">{{ item }}</h3>
      </el-carousel-item>
    </el-carousel>
  </el-card>
</template>

<script setup>
import { ref,computed,onMounted,onBeforeUnmount } from 'vue';
import { useStore } from 'vuex';
// import axios from 'axios';

const store = useStore()


const circleUrl = computed(() => {
  return store.state.userInfo.avatar
    ? store.state.userInfo.avatar
    : "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
})

// 使用 ref 来创建响应式的数据
const currentTime = ref(new Date().toLocaleTimeString());

let timer;

// 使用 onMounted 来在组件挂载时执行代码
onMounted(() => {
  // 使用 setInterval 每秒更新一次时间
  timer=setInterval(() => {
    currentTime.value = new Date().toLocaleTimeString();
  }, 1000);
});

// 使用 onBeforeUnmount 来在组件销毁前执行代码
onBeforeUnmount(() => {
  // 清除定时器
  clearInterval(timer);
});


</script>

<style lang="scss" scoped>
.box_card {
  margin-top: 50px;
}

.el-carousel__item h3 {
  color: #475669;
  opacity: 0.75;
  line-height: 200px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>
